﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace DynaBoard
{
    public class Thread
    {
        public readonly int Id;
        public readonly string Title;
        public readonly string Author;
        public readonly string Email;
        public readonly string StartedDateTime;
        public readonly string ActiveDateTime;
        public readonly string Url;
        public readonly int Children;

        public Thread(Post post)
            : this(post, Post.CountChildren(post.Id))
        { }

        public Thread(Post post, int children)
        {
            if (post == null)
            {
                throw new ArgumentNullException("post");
            }

            this.Id = post.Id;
            this.Title = post.Title;
            this.Author = post.AuthorName;
            this.Email = post.AuthorEmail;
            this.StartedDateTime = new TimePassed(post.PostedUtc, DateTimeKind.Utc);
            this.ActiveDateTime = new TimePassed(Post.LastActive(post.Id));
            this.Url = PostPage.UrlToPost(post.Id);
            this.Children = children;
        }
    }

}
